package com.tanhua.admin.controller;

import com.tanhua.admin.service.DashboardService;
import com.tanhua.model.vo.AnalysisDataVo;
import com.tanhua.model.vo.AnalysisSummaryVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/dashboard")
public class DashboardController {

    @Autowired
    private DashboardService dashboardService;


    /**
     * 概要统计信息
     * @return
     */
    @GetMapping("/summary")
    public ResponseEntity summary(){
        AnalysisSummaryVo analysisSummaryVo=dashboardService.summary();
        return ResponseEntity.ok(analysisSummaryVo);
    }

    /**
     * 新增、活跃用户、次日留存率
     * @return
     */
    @GetMapping("/users")
    public ResponseEntity users(@RequestParam Map<String,String> map){
        Long sd = Long.valueOf(map.get("sd"));
        Long ed = Long.valueOf(map.get("ed"));
        String type = (String) map.get("type");
        log.info("参数 sd{},ed{},type{}",sd,ed,type);
        AnalysisDataVo dataVo=dashboardService.analysisData(sd,ed,type);
        /*AnalysisDataVo dataVo = new AnalysisDataVo();
        List<Map<String,Object>> lastYear = new ArrayList<>();
        List<Map<String,Object>> thisYear = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            Map<String,Object> lastMap = new HashMap<>();
            lastMap.put("title",i+1);
            lastMap.put("amount",100+i);
            lastYear.add(lastMap);

            Map<String,Object> thisMap = new HashMap<>();
            thisMap.put("title",i+1);
            thisMap.put("amount",100+2);
            thisYear.add(thisMap);
        }
        dataVo.setLastYear(lastYear);
        dataVo.setThisYear(thisYear);*/
        return ResponseEntity.ok(dataVo);
    }
}
